<?php

class Admin_Model_Tmp extends Zend_Db_Table_Abstract {

    protected $_name = 'tmp';
    protected $_primary = 'id';

    public function getTmp($option = null, $params = null) {
    	$select = $this->select();
    	
    	if($option['task'] == 'admin-user'){
    		$userId = $params['userId'];	
        	$select->where('userId=?',$userId);
    	}elseif($option['task'] == 'admin-featureDetail'){
    		$userId = $params['userId'];
    		$featureDetailId = $params['featureDetailId'];
    		$select->where('userId=?',$userId)
    				->where('featureDetailId=?',$featureDetailId);
    	}
    	
        $result = $this->fetchAll($select);
        if ($result) {
            return $result->toArray();
        } else {
            return null;
        }
    }

    public function getTmpOne($id) {
        $select = $this->select()
                ->where('id = ?', $id);

        $result = $this->fetchRow($select);
        if ($result) {
            return $result->toArray();
        } else {
            return null;
        }
    }

    public function addItem($info) {
    	try {
	        $id = $this->insert($info);
	
	        return $id;
        } catch (Exception $e) {
        	throw $e;
        }
    }

    public function updateItem($id, $info) {
    	try {
	        $result = $this->update($info, "id=" . $id);
	        return $result;
        } catch (Exception $e) {
        	throw $e;
        }
    }

    public function deleteItem($id) {
    	try {
	        $result = $this->delete("id = '" . $id . "'");
	        
	       	return $result;
        } catch (Exception $e) {
        	throw $e;
        }
    }

    public function countItems() {
        $query = $this->select()
                ->from($this->_name, 'count(id) as total');
        $result = $this->fetchRow($query);
        if ($result) {
            return $result->total;
        } else {
            return null;
        }       
    }

}